package com.apes.fn.scm.purchaseReturn.model;

import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.plugin.fileserver.File;
import com.apes.framework.util.ApesConst;
import com.apes.scm.account.account.model.Cooperation;
import com.apes.scm.account.account.model.InventoryBatch;
import com.apes.scm.masterdata.party.model.PartyRole;
import com.apes.scm.masterdata.product.model.Product;
import com.apes.scm.masterdata.product.model.ProductUom;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.Date;

/**
 * @BelongsProject: apes-server
 * @BelongsPackage: com.apes.fn.scm.purchaseReturn.model
 * @ClassName: PurchaseAfterJuniorItem
 * @Author: ljp
 * @CreateTime: 2021-08-06 15:54
 * @Description: 售后工单明细
 * @Version: 1.0
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = PurchaseAfterJuniorItem.CONST_TABLE_NAME)
public class PurchaseAfterJuniorItem extends Model {
    public static final String CONST_TABLE_NAME = "purchase_after_junior_item";
    @Id
    @Column(name = "id")
    @ApesGenerator(code = CONST_TABLE_NAME, name = "售后工单明细")
    @Comment("编码")
    private String id;

    @NotNull
    @ManyToOne(optional = false)
    @JoinColumn(name = "purchaseAfterJunior_id", referencedColumnName = "id")
    @Comment("售后工单号")
    private PurchaseAfterJunior purchaseAfterJunior;

    @NotNull
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "product_id", referencedColumnName = "id")
    @Comment("商品")
    private Product product;

    @NotNull
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "product_uom_id", referencedColumnName = "id")
    @Comment("计量单位")
    private ProductUom uom;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "supplier_id", referencedColumnName = "id")
    @Comment("供应商")
    private PartyRole supplier;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "barch_code", referencedColumnName = "id")
    @Comment("批次内码")
    private InventoryBatch inventoryBatch;

    @Column(name = "price_unit", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("单价")
    private double priceUnit = 0;

    @Column(name = "purchase_in_date")
    @Comment("入库日期")
    private Date purchaseInDate;

    @Column(name = "product_qty", nullable = false, columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    @Comment("订单数量")
    private double productQty = 0.0;

    @Column(name = "return_qty", nullable = false, columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    @Comment("返厂数量")
    private double returnQty = 0.0;

    @Column(name = "note")
    @Comment("备注")
    private String note;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "cooperation_id", referencedColumnName = "id")
    @Comment("合作方式")
    private Cooperation cooperation; //合作方式

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "original_supplier_id", referencedColumnName = "id")
    @Comment("原供应商")
    private PartyRole originalSupplier;

    @Column(name = "original_inventory_batch")
    @Comment("原批次内码")
    private long originalInventoryBatch;

    @Column(name = "original_price_unit", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("原单价")
    private double originalPriceUnit = 0;

    @File
    @Lob
    @Comment("图片")
    @Basic(fetch = FetchType.LAZY)
    @Column(name = "imgs", columnDefinition = "CLOB")
    private String imgs;

    @Transient
    private String flag;//用于前端隐藏
}
